import Router from 'koa-router'
import { isExist, isExistEmail, login, register, sendEmail } from '../controller'

import idempotent from '../middlewares/redlock'
import validate from '../middlewares/validator'
import { isExistEmailRule, isExistRule, loginRule, registerRule, sendEmailRule } from './validatorRules'

const router = new Router()
router.prefix('/noauth')
router.post('/test', idempotent(), async function (ctx, next) {})

router.get('/isexist', validate(isExistRule), isExist)
router.get('/isexistemail', validate(isExistEmailRule), isExistEmail)
router.post('/register', idempotent(), validate(registerRule), register)
router.post('/login', idempotent(), validate(loginRule), login)
router.post('/sendemail', idempotent(), validate(sendEmailRule), sendEmail)

export default router
